package com.climaxi.core.helper;

import com.climaxi.core.Contants;

import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;

public class Database {

	public static boolean checkDataBase() 
	{
	    SQLiteDatabase checkDB = null;

	    try 
	    {
	        checkDB = SQLiteDatabase.openDatabase(Contants.LINK_DATABASE, null, SQLiteDatabase.OPEN_READONLY);
	    } 
	    catch(SQLiteException e) 
	    {
	        //database does't exist yet.
	    }

	    if(checkDB != null)
	    {
	        checkDB.close();
	    }
	    return checkDB != null ? true : false;
	}
	
	public static boolean createDatabase()
	{
		SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(Contants.LINK_DATABASE, null);
		if(database.isOpen())
		{
			return true;
		}
		return false;
	}
	
	public static boolean createTableDatabase()
	{
		if(Contants.IS_DATABASE)
		{
			SQLiteDatabase database = SQLiteDatabase.openDatabase(Contants.LINK_DATABASE, null, SQLiteDatabase.CREATE_IF_NECESSARY);
			//database.execSQL(GlobalVariable.SQL_CREATE_CLI_STORY);
			//database.execSQL(GlobalVariable.SQL_CREATE_CLI_CHAPTER);
			database.close();
			return true;
		}
		else
		{
			return false;
		}
	}
	
}
